package com.itheima.service.impl;

import com.itheima.dao.EmpDao;
import com.itheima.domain.Emp;
import com.itheima.service.EmpService;
import com.itheima.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class EmpServiceImpl implements EmpService {
    @Override
    public void add(Emp emp) {
        // 使用mybatis操作dao
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        EmpDao empDao = sqlSession.getMapper(EmpDao.class);
        empDao.add(emp);
        sqlSession.close();
    }

    @Override
    public List<Emp> findAll() {
        // 使用mybatis操作dao
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        EmpDao empDao = sqlSession.getMapper(EmpDao.class);
        List<Emp> list = empDao.findAll();
        sqlSession.close();
        return list;
    }
}
